<template>
	<section>
		<headers :txt="txt"></headers>
		<ul class="mu20">
			<li class="bbtm md10 sz30 wallfff flexs plr30  hei100">
				<label for="pwd1" class="flex_self w25">新密码</label>
				<input id="pwd1" v-model="pwd1" class="flex1 sz30" type="password" placeholder="输入新密码" />
			</li>
			<li class="bbtm md10 sz30 wallfff flexs plr30  hei100">
				<label for="pwd2" class="flex_self w25">确认密码</label>
				<input id="pwd2" v-model="pwd2" class="flex1 sz30" type="password" placeholder="再次输入新密码" />
			</li>
		</ul>
		<button class="btns mu30" type="button" @click="inits">确认</button>
	</section>
</template>

<script>
	import { Toast } from 'mint-ui';
	import { Indicator } from 'mint-ui';
	import Qs from 'qs';
	import md5 from 'js-md5';
	export default {
		data() {
			return {
				pwd1: "",
				pwd2: "",
				txt: this.$route.query.types=='login'?"设置登录密码":"设置支付密码",
			}
		},
		methods: {
			inits: function() {
				let v = this;
				if(!/^\w{6,12}$/.test(v.pwd1)) {
					Toast("请输入6-12位密码")
				} else if(v.pwd1 !== v.pwd2) {
					Toast("两次输入密码不相同")
				} else {
					Indicator.open({
						text: '请求中，请稍等'
					});

					this.$http.post("/WorkMembers/V1.0/SetInitPwd", Qs.stringify({
						"MembersID": this.$store.state.MembersID,
						"PwdType": v.$route.query.types,
						"Pwd": md5(v.pwd2)

					})).then((res) => {
						Indicator.close();
						if(!res.data.Return_ID) {
							if(v.$route.query.types == "login") {
								let session = JSON.parse(sessionStorage.infos);
								session.Members_HasLoginPwd = 1;
								sessionStorage.infos = JSON.stringify(session);
							} else {
								let session = JSON.parse(sessionStorage.infos);
								session.Members_HasPayPwd = 1;
								sessionStorage.infos = JSON.stringify(session);
							}
						}
						Toast(res.data.Return_Mess);

					}).catch((err) => {
						Indicator.close();
						Toast(err);
					});
				}
			}
		}
	}
</script>

<style>

</style>